package org.sean.framework.canary.loadbalancer.predicate;

import org.sean.framework.canary.core.CanaryUtils;
import org.sean.framework.canary.loadbalancer.CanaryPredicate;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.http.HttpHeaders;


/**
 * 选择主干版本
 *
 * @author xielei
 */
public class LocalLabelPredicate extends CanaryPredicate {

    public boolean getSelector(ServiceInstance server, HttpHeaders headers) {
        String localLabel = CanaryUtils.getLocalLabel();
        String serverLabel = CanaryUtils.getServerLabel(server);
        boolean result = localLabel.equalsIgnoreCase(serverLabel);
        String serverName = server.getServiceId();
        logger.debug("[{}] : {} -label : [{}] -- rule label : [{}] -- match result : [{}]",
                serverName, server.getUri(), serverLabel, localLabel, result);
        return result;
    }
}
